
const WXAPI = require('apifm-wxapi')
var app = getApp()
Page({
  data: {
    addressList:[]
  },

  async selectTap (e) {
    var id = e.currentTarget.dataset.id;
    const res = await WXAPI.selectDefaultAddress({
      addressId: id
    });
    console.log("获取地址成功"+JSON.stringify(res))
    this.initShippingAddress();
    wx.showModal({
      title: '提示',
      content: payRes.msg,
      showCancel: false
    })
  },

  addAddess : function () {
    wx.navigateTo({
      url:"/pages/address-add/index"
    })
  },
  
  editAddess: function (e) {
    wx.navigateTo({
      url: "/pages/address-add/index?id=" + e.currentTarget.dataset.id
    })
  },
  
  onLoad: function () {
    console.log('onLoad')

   
  },
  onShow : function () {
    this.initShippingAddress();
  },

  async initShippingAddress () {
    var that = this;
    const res = await WXAPI.initShippingAddress({
      userId: wx.getStorageSync('userid')
    });
    console.log("获取地址成功"+JSON.stringify(res))
    if (res.code == 20000) {
      that.setData({
        addressList:res.data
      });
    } else {
      that.setData({
        addressList: null
      });
    }
    
  }
})
